package com.augurit.wf.common.extmodel;

import java.util.ArrayList;
import java.util.List;

import org.jbpm.api.ProcessDefinition;
import com.augurit.wf.common.service.IWfService;

/**
 * 流程版本树根节点
 *
 */
public class ProccessReleaseRootTreeNode extends ProcessReleaseTreeNode{
	
	/**
	 * 构造函数
	 */
	public ProccessReleaseRootTreeNode(){
		this.type = ProcessReleaseTreeNode.ROOT_NODE;
	}
	
	@Override
	public List<ProcessReleaseTreeNode> getChildNodes(IWfService wfService){
		List<ProcessDefinition> list = wfService.getProcDefIgnoreVersion();
		return this.convertToTreeNode(list);
	}
	
	/**
	 * 转换为
	 * @param list
	 * @return
	 */
	private  List<ProcessReleaseTreeNode> convertToTreeNode(List<ProcessDefinition> list){
		List<ProcessReleaseTreeNode> nodes = null;
		if(list != null && list.size() > 0){
			nodes = new ArrayList<ProcessReleaseTreeNode>();
			for(ProcessDefinition procDef:list){
				ProcessReleaseTreeNode treeNode = new ProcessNameTreeNode(procDef.getKey());
				treeNode.setText(procDef.getName());
				nodes.add(treeNode);
			}
		}
		return nodes;
	}
	
	
}
